The purpose of this markdown is to report analytic accuracy by calculating the counts of simultaneous pairs, distributions across those pairs, correlation, and Bland-Altman analysis. Also includes the time-to-result numbers and figure.
First we load the necessary packages:
suppressPackageStartupMessages({
# Data frame manipulation
require(dplyr)
# Graphics and output
require(ggplot2)
# Bland Altman
require(BlandAltmanLeh)
})
Ensure the environmental variables are specified:
if (Sys.getenv('PICU_LAB_DATA_PATH') == '' |
Sys.getenv('PICU_LAB_IMG_PATH') == '' |
Sys.getenv('PICU_LAB_IN_FILE') == '' |
Sys.getenv('PICU_LAB_SITE_NAME') == '' |
Sys.getenv('PICU_LAB_RUN_DATE') == '')
stop('Missing necessary environmental variables - see README.md')
cat(sprintf('Site: %s\n', Sys.getenv('PICU_LAB_SITE_NAME')))
## Site: CHOP
Specify the run date:
run.date <- Sys.getenv('PICU_LAB_RUN_DATE')
cat(sprintf('Run Date: %s\n', run.date))
## Run Date: 2022-12-22
Load data from the DATA_PATH with the associated IN_FILE, adding a file separator between them. This should result in loading two data frames: cohort.df and labs.df.
load(
file = file.path(
Sys.getenv('PICU_LAB_DATA_PATH'),
Sys.getenv('PICU_LAB_IN_FILE')
)
)
We will utilize several sensitivity analyses in this markdown. To simplify, we set several parameters ahead of time and then run through those parameters below.
# The primary cutoff value between collection times (in minutes) to
# determine "simultaneous"
primary.cutoff <- 15.
# Sensitivity analysis list
sens.cutoffs <- c(1., 30., 90.)
First we create the joined dataset to represent simultaneously obtained lab values. We need to allow the specifying of the two PROC_NAME comparators from the list - CBC, BG, or ISTAT. We also need to include several parameters that can be adjusted to reflect sensitivity analyses:
ORDER_PROC_KEY values)We will remove non-numeric rows, as there is no sensitivity analysis to do with these but rather we have reported their counts already. Below is the function to be used (note that this may be duplicated in other Rmarkdown files - changes should be made here and not in other files):
#'
#' @title Create Paired Dataset
#'
#' @description Creates a dataset of paired simultaneous lab values
#'
#' @param labs.df The labs data frame
#' @param cohort.df The cohort data frame, needed for PAT_KEY and DEPT
#' @param PN A two-element list of PROC_NAMEs to join
#' @param time.diff The max time difference (min) between collected times
#' @param CN The COMP_NAME to join [Default: 'Hgb']
#' @param multi.per.pt If FALSE, limit to first result per patient, otherwise
#' if TRUE [Default], allow all
#'
#' @returns The resulting joined data frame
#'
createPairedDataset <- function (labs.df, cohort.df, PN, time.diff,
CN = 'Hgb', multi.per.pt = T) {
# First we filter to remove the non-numeric rows
filter.df <-
labs.df %>%
dplyr::filter(!is.na(NUM_VAL) & NUM_VAL != 9999999.) %>%
dplyr::filter(COMP_NAME == CN)
cat(sprintf('Number of component numeric rows in input data frame: %d\n',
nrow(filter.df)))
# Join to get PAT_KEY and DEPT, used in subsequent filtering
keyed.df <-
dplyr::left_join(
x = filter.df,
y = cohort.df %>%
dplyr::select(ENC_KEY, PAT_KEY, DEPT),
by = c('ENC_KEY')
)
# Now we filter by PN and join to create full data frame
joined.df <-
dplyr::inner_join(
x = keyed.df %>%
dplyr::filter(PROC_NAME == PN[1]) %>%
dplyr::select(ENC_KEY, PAT_KEY, ORDER_PROC_KEY,
DEPT, COLLECTED_DT, RESULT_DT, NUM_VAL, AGE_PROC),
y = keyed.df %>%
dplyr::filter(PROC_NAME == PN[2]) %>%
dplyr::select(ENC_KEY, PAT_KEY, ORDER_PROC_KEY,
DEPT, COLLECTED_DT, RESULT_DT, NUM_VAL),
by = c('ENC_KEY', 'PAT_KEY', 'DEPT'),
suffix = c('.x', '.y')
)
# Join using base R, by column number
# [[5]] is PN[1] COLLECTED_DT
# [[10]] is PN[2] COLLECTED_DT
joined.df$COLL_TIME_DIFF_MIN <-
as.numeric(joined.df[[5]] - joined.df[[10]], units = 'mins')
# Apply the cutoff time
cutoff.df <-
joined.df %>%
dplyr::filter(abs(COLL_TIME_DIFF_MIN) < time.diff)
cat(sprintf('Number of paired, simultaneous values meeting cutoff: %d\n',
nrow(cutoff.df)))
# Ensure that each first PROC_NAME order is only used once - meaning that
# each ORDER_PROC_KEY.x should be unique
unique.x.df <-
cutoff.df%>%
dplyr::arrange(ORDER_PROC_KEY.x, COLL_TIME_DIFF_MIN) %>%
dplyr::group_by(ORDER_PROC_KEY.x) %>%
dplyr::summarize(
ORDER_PROC_KEY.y = first( ORDER_PROC_KEY.y ),
DEPT = first( DEPT ),
COLLECTED_DT.x = first( COLLECTED_DT.x ),
RESULT_DT.x = first( RESULT_DT.x ),
NUM_VAL.x = first( NUM_VAL.x ),
COLLECTED_DT.y = first( COLLECTED_DT.y ),
RESULT_DT.y = first( RESULT_DT.y ),
NUM_VAL.y = first( NUM_VAL.y ),
COLL_TIME_DIFF_MIN = first( COLL_TIME_DIFF_MIN ),
AGE_PROC = first( AGE_PROC ),
ENC_KEY = first( ENC_KEY ),
PAT_KEY = first( PAT_KEY )
) %>%
dplyr::ungroup()
cat(sprintf('Number of non-duplicated first PROC_NAME rows: %d\n',
nrow(unique.x.df)))
# Similarly, ensure that each second PROC_NAME order is being used just once
# (i.e., that ORDER_PROC_KEY.y is not duplicated)
non.dup.df <-
unique.x.df %>%
dplyr::arrange(ORDER_PROC_KEY.y, COLL_TIME_DIFF_MIN) %>%
dplyr::group_by(ORDER_PROC_KEY.y) %>%
dplyr::summarize(
ORDER_PROC_KEY.x = first( ORDER_PROC_KEY.x ),
DEPT = first( DEPT ),
COLLECTED_DT.x = first( COLLECTED_DT.x ),
RESULT_DT.x = first( RESULT_DT.x ),
NUM_VAL.x = first( NUM_VAL.x ),
COLLECTED_DT.y = first( COLLECTED_DT.y ),
RESULT_DT.y = first( RESULT_DT.y ),
NUM_VAL.y = first( NUM_VAL.y ),
COLL_TIME_DIFF_MIN = first( COLL_TIME_DIFF_MIN ),
AGE_PROC = first( AGE_PROC ),
ENC_KEY = first( ENC_KEY ),
PAT_KEY = first( PAT_KEY )
) %>%
dplyr::ungroup()
cat(sprintf('Number of non-duplicated second PROC_NAME rows: %d\n',
nrow(non.dup.df)))
# Do we limit by one per patient?
if (!multi.per.pt) {
per.pt.df <-
non.dup.df %>%
# Sort by PAT_KEY and the first COLLECTED DT
dplyr::arrange(PAT_KEY, COLLECTED_DT.x) %>%
# Group by PAT_KEY and add a "LINE" number
dplyr::group_by(PAT_KEY) %>%
dplyr::mutate(
PAT_LINE = row_number()
) %>%
# Ungroup
dplyr::ungroup() %>%
# Filter for lines == 1 only
dplyr::filter(PAT_LINE == 1) %>%
dplyr::select(-PAT_LINE)
} else {
per.pt.df <- non.dup.df
}
cat(sprintf('Number of paired, simultaneous values: %d\n',
nrow(per.pt.df)))
cat(sprintf('Number of duplicated ORDER_PROC_KEY.x values: %d\n',
sum(duplicated(per.pt.df$ORDER_PROC_KEY.x))))
return(per.pt.df)
}
First we create the CBC - BG dataset using the primary cutoff value, and include all pairs per patient.
cbc.bg <- createPairedDataset(
labs.df = labs.df,
cohort.df = cohort.df,
PN = c('CBC', 'BG'),
CN = 'Hgb',
time.diff = primary.cutoff,
multi.per.pt = T
)
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 72997
## Number of non-duplicated first PROC_NAME rows: 67141
## Number of non-duplicated second PROC_NAME rows: 67077
## Number of paired, simultaneous values: 67077
## Number of duplicated ORDER_PROC_KEY.x values: 0
From this dataset we can get counts of lab values per DEPT:
table(cbc.bg$DEPT)
##
## CICU PICU
## 24391 42686
Now we describe the distributions:
#'
#' @title Describe Paired Distributions
#'
#' @description Descriptive statistics, QQ plots, density plot, and TTest
#'
#' @param df The paired data frame of interest
#' @param PN A 2-element list (matching that from above) of the PROC_NAMEs
#' @param paired.t If TRUE [Default], uses paired t test
#' @param to.return If TRUE, returns list of results; otherwise returns NULL [Default]
#'
#' @returns Pending the above flag, either NULL or list of graphics and t test
#'
describePairedDistributions <- function (df, PN,
paired.t = T, to.return = F) {
cat(sprintf('Summary of %s values:\n', PN[1]))
print(summary(df$NUM_VAL.x))
cat(sprintf('SD: %0.2f\n', sd(df$NUM_VAL.x)))
# QQ Plot
p1 <-
df %>%
ggplot(aes(sample = NUM_VAL.x)) +
stat_qq() +
ggtitle(paste0('Lab Value Distribution QQ Plot: ',PN[1])) +
theme_bw()
print(p1)
cat(sprintf('Summary of %s values:\n', PN[2]))
print(summary(df$NUM_VAL.y))
cat(sprintf('SD: %0.2f\n', sd(df$NUM_VAL.y)))
# QQ Plot
p2 <-
df %>%
ggplot(aes(sample = NUM_VAL.y)) +
stat_qq() +
ggtitle(paste0('Lab Value Distribution QQ Plot: ',PN[2])) +
theme_bw()
print(p2)
# Create Density Plot
Density <-
rbind(
data.frame(
df %>%
dplyr::select(NUM_VAL.x) %>%
dplyr::rename(val = NUM_VAL.x),
src = PN[1]),
data.frame(
df %>%
dplyr::select(NUM_VAL.y) %>%
dplyr::rename(val = NUM_VAL.y),
src = PN[2])
) %>%
ggplot() +
geom_density(aes(x = val, fill = src), alpha = 0.5) +
scale_fill_brewer(type = 'qual', palette = 6) +
labs(fill = 'Source') +
xlab('Hemoglobin (g/dL)') +
ylab('Density (Distribution)') +
theme_bw()
print(Density)
# Paired T-Test
t.res <-
t.test(
x = df$NUM_VAL.x,
y = df$NUM_VAL.y,
alternative = 'two.sided',
paired = TRUE
)
print(t.res)
# Return
if (to.return) {
return(list(
qq.p = list(p1, p2),
density.p = Density,
t.test = t.res
))
} else {
return()
}
}
Describe the primary paired distribution and capture the results, as we will have to save out these images for compilation with other sites.
paired.res <- describePairedDistributions(
df = cbc.bg,
PN = c('CBC', 'BG'),
paired.t = T,
to.return = T
)
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.50 9.30 10.70 10.97 12.40 23.20
## SD: 2.39
## Summary of BG values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.80 9.90 11.30 11.55 12.90 25.00
## SD: 2.40
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -211.99, df = 67076, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.5843414 -0.5736353
## sample estimates:
## mean difference
## -0.5789883
Now we evaluate the correlation among these paired values:
#'
#' @title Determine Correlation
#'
#' @description Determine the Pearson Correlation among pairs by DEPT
#'
#' @param df The labs data frame
#' @param DPT Either a single DEPT value or a list of values
#'
#' @returns A list of results containing cor estimates, CI, sample size
#'
determineCorrelation <- function (df, DPT) {
# Filter by the department of interest first
limited.df <-
df %>%
dplyr::filter(DEPT %in% DPT)
cat(sprintf('Number of rows from which correlation is calculated: %d\n',
nrow(limited.df)))
# Calculated from cor, with CIs calculated manually
cat(sprintf('First we use `cor` function to calculate:\n'))
R <- cor(limited.df$NUM_VAL.x,limited.df$NUM_VAL.y)
R2 <- R * R
cat(sprintf('\tCorrelation (R): %0.4f\tR^2: %0.4f\n',
R, R2))
n <- nrow(limited.df)
k <- 2
SE <- sqrt((4*R2*((1-R2)**2)*((n-k-1)**2))/((n**2-1)*(n + 3)))
cat(sprintf('\tCI: Lower: %0.4f\tUpper: %0.4f\n',
R2 - 2*SE, R2 + 2*SE))
# Calculated from cor.test
cat(sprintf('Now we use `cor.test` and `conf.int` to calculate:\n'))
cor.res <-
cor.test(
x = limited.df$NUM_VAL.x,
y = limited.df$NUM_VAL.y,
alternative = 'two.sided',
method = 'pearson'
)
cat(sprintf('\tCalculated R: %0.4f\tR^2: %0.4f\n',
cor.res$estimate,
cor.res$estimate * cor.res$estimate))
cat(sprintf('\tCalulated CIs: Lower: %0.4f\tUpper: %0.4f\n',
cor.res$conf.int[1]*cor.res$conf.int[1],
cor.res$conf.int[2]*cor.res$conf.int[2]))
return(list(
cor.est = cor.res$estimate,
cor.conf.int = cor.res$conf.int,
dept = DPT,
n = nrow(limited.df)
))
}
Now we compute the Pearson correlations among all pairs, and then subsequently among the different departments. These will be saved out later for comparison between institutions.
pcc.cbc.bg <- determineCorrelation(cbc.bg, c('PICU', 'CICU'))
## Number of rows from which correlation is calculated: 67077
## First we use `cor` function to calculate:
## Correlation (R): 0.9564 R^2: 0.9148
## CI: Lower: 0.9135 Upper: 0.9160
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9564 R^2: 0.9148
## Calulated CIs: Lower: 0.9135 Upper: 0.9160
pcc.cbc.bg.picu <- determineCorrelation(cbc.bg, 'PICU')
## Number of rows from which correlation is calculated: 42686
## First we use `cor` function to calculate:
## Correlation (R): 0.9159 R^2: 0.8389
## CI: Lower: 0.8360 Upper: 0.8417
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9159 R^2: 0.8389
## Calulated CIs: Lower: 0.8360 Upper: 0.8416
pcc.cbc.bg.cicu <- determineCorrelation(cbc.bg, 'CICU')
## Number of rows from which correlation is calculated: 24391
## First we use `cor` function to calculate:
## Correlation (R): 0.9750 R^2: 0.9506
## CI: Lower: 0.9494 Upper: 0.9519
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9750 R^2: 0.9506
## Calulated CIs: Lower: 0.9494 Upper: 0.9518
We can compare Pearson correlation coefficients using this function:
#'
#' @title Compare Pearson Correlations
#'
#' @description Use the Fisher's R to Z transformation and return significance
#'
#' @param r1 The R value from the first independent correlation
#' @param n1 The sample size of the first correlation
#' @param r2 The R value from the second independent correlation
#' @param n2 The sample size of the second correlation
#'
#' @returns The p-value
#'
#'
comparePearsonCorrelations <- function (r1, n1, r2, n2) {
z1 <- atanh(r1)
z2 <- atanh(r2)
zobs <- (z1-z2) / sqrt( 1 / (n1-3) + 1 / (n2-3) )
pval <- 2 * pnorm(-abs(zobs))
return(pval)
}
Compare PICU vs CICU correlations:
cat(sprintf('PICU (R: %0.4f) vs CICU (R: %0.4f): %0.4f\n',
pcc.cbc.bg.picu$cor.est,
pcc.cbc.bg.cicu$cor.est,
comparePearsonCorrelations(
r1 = pcc.cbc.bg.picu$cor.est,
n1 = pcc.cbc.bg.picu$n,
r2 = pcc.cbc.bg.cicu$cor.est,
n2 = pcc.cbc.bg.cicu$n
)))
## PICU (R: 0.9159) vs CICU (R: 0.9750): 0.0000
In this section we make use of the package BlandAltmanLeh to perform the calculations and generate the statistical results.
#'
#' @title Perform Bland Altman Analysis
#'
#' @description Calculates Bland-Altman statistics and generates plots
#'
#' @param df The data frame of paired values
#' @param PN A 2-element list of the PROC Names for comparison
#' @param DPT A list or single value of the departments of interest
#' @param pt.size The point size for plotting the B-A plots [Default: 0.8]
#' @param to.graph If TRUE [Default], displays BA plots
#' @param to.return If TRUE [Default], returns a list of elements including:
#'
#' @returns Either a list as denoted above, or NULL if `to.return` is FALSE
#'
performBlandAltmanANalysis <- function (df, PN, DPT, pt.size = 0.8,
to.graph = T, to.return = T,
non.param = NA) {
# Filter by the department of interest first
limited.df <-
df %>%
dplyr::filter(DEPT %in% DPT) %>%
dplyr::mutate(
diff = NUM_VAL.x - NUM_VAL.y
) %>%
dplyr::arrange(diff)
cat(sprintf('Number of rows from which correlation is calculated: %d\n',
nrow(limited.df)))
# If percentile ranges are given for non-parametric BA, trim data:
if (any(!is.na(non.param))) {
if (length(non.param) != 2)
stop('If non.param is specified, must be length == 2')
# Calculate lower and upper quantiles at the specified probabilities
lower <- quantile(limited.df$diff, probs = non.param[1])
upper <- quantile(limited.df$diff, probs = non.param[2])
# Keep only those rows where the diff falls within lower and upper
limited.df <-
limited.df %>%
dplyr::filter(
diff >= lower & diff <= upper
)
cat(sprintf('Lower %0.2f %%: %0.3f\tUpper %0.2f %%: %0.3f\n',
non.param[1] * 100., lower,
non.param[2] * 100., upper))
cat(sprintf('New number of rows: %d\n', nrow(limited.df)))
}
# QQ Plot of mean differences
p.qq <-
limited.df %>%
ggplot(aes(sample = diff)) +
stat_qq() +
ggtitle('QQ Plot of Differences') +
theme_bw()
if (to.graph)
print(p.qq)
# Do not use a test for normality unless number of samples < 5000
if (nrow(limited.df) < 5000) {
print( shapiro.test(limited.df$diff) )
}
# For ease of subsequent coding, rename vectors:
x <- limited.df$NUM_VAL.x
y <- limited.df$NUM_VAL.y
# Run the BA statistics
stats <-
BlandAltmanLeh::bland.altman.stats(
group1 = x,
group2 = y
)
# Display results
cat(sprintf('B-A Analysis of %s - %s in DEPT %s\n',
PN[1],PN[2],DPT))
cat(sprintf('\tMean difference (bias): %0.4f\n',
stats$mean.diffs))
cat(sprintf('Limits: [%0.2f, %0.2f]\n',
stats$lower.limit, stats$upper.limit))
cat(sprintf('CIs of mean and limits:\n'))
print(stats$CI.lines)
# Make Graph
mean.diff <- mean( x - y )
sd.diff <- sd( x - y )
p <-
ggplot() +
geom_point(aes(x = (x + y) / 2., y = (x - y)), size = pt.size) +
geom_hline(aes(yintercept = mean.diff), color = 'blue', size = 0.5) +
geom_hline(aes(yintercept = mean.diff + (1.96 * sd.diff)),
color = 'red', linetype = 'dashed', size = 0.5) +
geom_hline(aes(yintercept = mean.diff - (1.96 * sd.diff)),
color = 'red', linetype = 'dashed', size = 0.5) +
xlab('Average Value') +
ylab('Difference') +
theme_bw()
if (to.graph) {
print(p)
}
# Return
if (to.return) {
return(
list(
stats = stats,
plot = p,
qq.plot = p.qq
))
} else {
return()
}
}
Perform Bland-Altman, split by department:
ba.all <- performBlandAltmanANalysis(
df = cbc.bg,
PN = c('CBC', 'BG'),
DPT = c('PICU', 'CICU'),
to.graph = T,
to.return = T,
non.param = NA
)
## Number of rows from which correlation is calculated: 67077
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5790
## Limits: [-1.97, 0.81]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.9746589 -1.9561154 -0.5843414
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5736353 0.7981387 0.8166822
ba.picu <- performBlandAltmanANalysis(
df = cbc.bg,
PN = c('CBC', 'BG'),
DPT = 'PICU',
to.graph = T,
to.return = T
)
## Number of rows from which correlation is calculated: 42686
## B-A Analysis of CBC - BG in DEPT PICU
## Mean difference (bias): -0.6324
## Limits: [-2.16, 0.90]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.1746252 -2.1489812 -0.6397577
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.6249521 0.8842714 0.9099155
ba.cicu <- performBlandAltmanANalysis(
df = cbc.bg,
PN = c('CBC', 'BG'),
DPT = 'CICU',
to.graph = T,
to.return = T
)
## Number of rows from which correlation is calculated: 24391
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.4856
## Limits: [-1.55, 0.58]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.5649226 -1.5412442 -0.4924284
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.4787577 0.5700581 0.5937365
Based on non-normally distributed differences, run non-parametric B-A by limiting percentiles for analysis:
ba.all.non.param <- performBlandAltmanANalysis(
df = cbc.bg,
PN = c('CBC', 'BG'),
DPT = c('PICU', 'CICU'),
to.graph = T,
to.return = T,
non.param = c(0.025, 0.975)
)
## Number of rows from which correlation is calculated: 67077
## Lower 2.50 %: -2.000 Upper 97.50 %: 0.600
## New number of rows: 63989
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5579
## Limits: [-1.33, 0.22]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.3375853 -1.3269811 -0.5609868
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5548644 0.2111299 0.2217342
Next we describe the differences in time-to-result, which is the difference between resulted time and collected time:
#'
#' @title Describe Time To Result
#'
#' @description Compares and describes the time to result between PROCs
#'
#' @param df The labs data frame
#' @param PN A 2-element list of the PROC NAMEs
#' @param WILCOX.CI If TRUE, computes Wilcoxon signed rank confidence intervals
#'
#' @returns A list containing the plot and Wilcoxon results
#'
#'
describeTimeToResult <- function (df, PN, WILCOX.CI = F) {
# Create the Time-To-Result data frame
time_to_result <-
rbind(
data.frame(
TTR = as.numeric(df$RESULT_DT.x - df$COLLECTED_DT.x, units = 'mins'),
SRC = PN[1]
),
data.frame(
TTR = as.numeric(df$RESULT_DT.y - df$COLLECTED_DT.y, units = 'mins'),
SRC = PN[2]
)
)
ttr.quint <- quantile(time_to_result$TTR, c(0.01, 0.99))
# Set the colors on the panel
panel.colors <- RColorBrewer::brewer.pal(3,"Set1")
src.vec <- vector()
src.vec[[PN[1]]] <- panel.colors[1]
src.vec[[PN[2]]] <- panel.colors[2]
# Plot
TTR.p <-
time_to_result %>%
dplyr::filter(TTR > ttr.quint[1] & TTR <= ttr.quint[2]) %>%
ggplot() +
geom_density(aes(x = TTR, fill = SRC), alpha = 0.5) +
scale_fill_manual(values = src.vec) +
coord_cartesian(xlim = c(0, 150)) +
xlab('Time To Result (Resulted - Collected Timestamp, min)') +
ylab('Density') +
labs(fill = 'Source') +
theme_bw()
print(TTR.p)
# Display summary statistics
cat(sprintf('Summary of Time-To-Result for %s\n', PN[1]))
print(summary(time_to_result$TTR[time_to_result$SRC == PN[1]]))
cat(sprintf('Summary of Time-To-Result for %s\n', PN[2]))
print(summary(time_to_result$TTR[time_to_result$SRC == PN[2]]))
# Determine normality
p1 <-
time_to_result %>%
dplyr::filter(SRC == PN[1]) %>%
ggplot(aes(sample = TTR)) +
stat_qq() +
ggtitle(paste0('TTR QQ Plot: ',PN[1])) +
theme_bw()
print(p1)
p2 <-
time_to_result %>%
dplyr::filter(SRC == PN[2]) %>%
ggplot(aes(sample = TTR)) +
stat_qq() +
ggtitle(paste0('TTR QQ Plot: ',PN[2])) +
theme_bw()
print(p2)
# Determine significant difference by non-parametric Wilcoxon signed rank test
# Note that we use paired statistics here because these are paired samples
wilcox.res <-
wilcox.test(
x = time_to_result$TTR[time_to_result$SRC == PN[1]],
y = time_to_result$TTR[time_to_result$SRC == PN[2]],
alternative = 'two.sided',
paired = TRUE,
conf.int = WILCOX.CI
)
print(wilcox.res)
# Return
return(list(
plot = TTR.p,
wilcox.res = wilcox.res
))
}
Capture the graphic so that we can save it out:
TTR.p <- describeTimeToResult(
df = cbc.bg,
PN = c('CBC', 'BG'),
WILCOX.CI = F
)
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -101.00 28.00 45.00 68.22 65.00 33795.00
## Summary of Time-To-Result for BG
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -1404.00 12.00 16.00 22.53 22.00 27487.00
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 2.135e+09, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
Save out our primary cutoff analytic data, for use when combining with other sites.
save(
file = file.path(
Sys.getenv('PICU_LAB_DATA_PATH'),
paste0(
Sys.getenv('PICU_LAB_SITE_NAME'),
'_pri_cbc_bg_analytic_',
run.date, '.rData'
)
),
primary.cutoff,
paired.res,
pcc.cbc.bg, pcc.cbc.bg.picu, pcc.cbc.bg.cicu,
ba.all, ba.picu, ba.cicu, ba.all.non.param,
TTR.p
)
If the lab results data frame contains ISTAT results, we must also complete those analyses. Using the functions written above, all of those are collapsed into a single function (below). Inside this function we:
#'
#' @title Run All Analytic
#'
#' @description Runs through all analytic analyses, for sensitivity analyses
#'
#' @param labs.df The original labs data frame
#' @param cohort.df The original cohort data frame
#' @param compare.PN The comparison PROC name (e.g. either `BG` or `ISTAT`)
#' @param time.diff The cutoff time difference (in minutes) for determining
#' whether labs are "simultaneous"
#' @param multi.per.pt If TRUE, allows all results from patients;
#' If FALSE, only the first (chronological) result from a patient is included
#' @param run.date A string representation of date for saving (format: %Y-%m-%d)
#' @param save.fn The file name (which will be concatenated with SITE and run.date),
#' or NA [Default] if we do not wish to save any results to a file
#'
runAllAnalytic <- function (labs.df, cohort.df, compare.PN,
time.diff, multi.per.pt, run.date, save.fn = NA) {
# Create paired dataset
paired.df <- createPairedDataset(
labs.df = labs.df,
cohort.df = cohort.df,
PN = c('CBC', compare.PN),
CN = 'Hgb',
time.diff = time.diff,
multi.per.pt = multi.per.pt
)
# Counts by department
print(table(paired.df$DEPT))
# Describe paired distribution
paired.res <- describePairedDistributions(
df = paired.df,
PN = c('CBC', compare.PN),
paired.t = T,
to.return = T
)
# Correlations
pcc <- determineCorrelation(paired.df, c('PICU', 'CICU'))
pcc.picu <- determineCorrelation(paired.df, 'PICU')
pcc.cicu <- determineCorrelation(paired.df, 'CICU')
cat(sprintf('PICU (R: %0.4f) vs CICU (R: %0.4f): %0.4f\n',
pcc.picu$cor.est,
pcc.cicu$cor.est,
comparePearsonCorrelations(
r1 = pcc.picu$cor.est,
n1 = pcc.picu$n,
r2 = pcc.cicu$cor.est,
n2 = pcc.cicu$n
)))
# Bland Altman Analysis
ba.all <- performBlandAltmanANalysis(
df = paired.df,
PN = c('CBC', compare.PN),
DPT = c('PICU', 'CICU'),
to.graph = T,
to.return = T
)
ba.picu <- performBlandAltmanANalysis(
df = paired.df,
PN = c('CBC', compare.PN),
DPT = 'PICU',
to.graph = T,
to.return = T
)
ba.cicu <- performBlandAltmanANalysis(
df = paired.df,
PN = c('CBC', compare.PN),
DPT = 'CICU',
to.graph = T,
to.return = T
)
# Bland Altman Analysis
ba.all.non.param <- performBlandAltmanANalysis(
df = paired.df,
PN = c('CBC', compare.PN),
DPT = c('PICU', 'CICU'),
to.graph = T,
to.return = T,
non.param = c(0.025, 0.0975)
)
# Time-to-result
TTR.p <- describeTimeToResult(
df = paired.df,
PN = c('CBC', compare.PN),
WILCOX.CI = F
)
# Save out?
if (! any(is.na(save.fn)) ) {
save(
file = file.path(
Sys.getenv('PICU_LAB_DATA_PATH'),
paste0(
Sys.getenv('PICU_LAB_SITE_NAME'),
'_', save.fn, '_',
run.date, '.rData'
)
),
time.diff, multi.per.pt,
paired.res,
pcc, pcc.picu, pcc.cicu,
ba.all, ba.picu, ba.cicu, ba.all.non.param,
TTR.p
)
}
}
Now we run for the POC values using the primary cutoff, allowing all results per patient (if the PROC exists):
if ('ISTAT' %in% unique(labs.df$PROC_NAME)) {
runAllAnalytic(
labs.df,
cohort.df,
compare.PN = 'ISTAT',
time.diff = primary.cutoff,
multi.per.pt = T,
run.date = run.date,
save.fn = 'pri_cbc_istat_analytic'
)
}
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 3802
## Number of non-duplicated first PROC_NAME rows: 3581
## Number of non-duplicated second PROC_NAME rows: 3575
## Number of paired, simultaneous values: 3575
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 1206 2369
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.50 9.30 10.90 11.21 12.80 22.80
## SD: 2.70
## Summary of ISTAT values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.40 9.20 11.20 11.34 13.30 23.80
## SD: 3.03
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -6.548, df = 3574, p-value = 6.664e-11
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.17537676 -0.09455331
## sample estimates:
## mean difference
## -0.134965
##
## Number of rows from which correlation is calculated: 3575
## First we use `cor` function to calculate:
## Correlation (R): 0.9138 R^2: 0.8350
## CI: Lower: 0.8249 Upper: 0.8451
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9138 R^2: 0.8350
## Calulated CIs: Lower: 0.8249 Upper: 0.8446
## Number of rows from which correlation is calculated: 2369
## First we use `cor` function to calculate:
## Correlation (R): 0.8896 R^2: 0.7913
## CI: Lower: 0.7761 Upper: 0.8066
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8896 R^2: 0.7913
## Calulated CIs: Lower: 0.7759 Upper: 0.8058
## Number of rows from which correlation is calculated: 1206
## First we use `cor` function to calculate:
## Correlation (R): 0.9022 R^2: 0.8140
## CI: Lower: 0.7947 Upper: 0.8332
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9022 R^2: 0.8140
## Calulated CIs: Lower: 0.7941 Upper: 0.8321
## PICU (R: 0.8896) vs CICU (R: 0.9022): 0.0702
## Number of rows from which correlation is calculated: 3575
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92481, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.1350
## Limits: [-2.55, 2.28]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.62045603 -2.48046571 -0.17537676
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.09455331 2.21053564 2.35052596
## Number of rows from which correlation is calculated: 2369
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92832, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## Mean difference (bias): -0.0661
## Limits: [-2.33, 2.19]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.40596654 -2.24507734 -0.11250634
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.01961692 2.11295409 2.27384328
## Number of rows from which correlation is calculated: 1206
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.91981, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.2703
## Limits: [-2.95, 2.41]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.0810291 -2.8137260 -0.3474788
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.1931513 2.2730959 2.5403989
## Number of rows from which correlation is calculated: 3575
## Lower 2.50 %: -2.600 Upper 9.75 %: -1.500
## New number of rows: 275
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.90752, p-value = 5.704e-12
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -1.9211
## Limits: [-2.60, -1.24]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.669201 -2.527139 -1.962101
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.880081 -1.315043 -1.172981
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.00 30.00 47.00 72.87 65.00 11099.00
## Summary of Time-To-Result for ISTAT
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -48.0 7.0 11.0 126.2 42.0 12058.0
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 4321838, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
Now we complete some of the same above measures using different permutations, as sensitivity analyses.
First we change the parameters to require a single value per patient. We run this across both BG and ISTAT pairs (if they exist).
for (proc.option in c('BG', 'ISTAT')) {
if (proc.option %in% unique(labs.df$PROC_NAME)) {
runAllAnalytic(
labs.df,
cohort.df,
compare.PN = proc.option,
time.diff = primary.cutoff,
multi.per.pt = F, # This is the change in this section
run.date = run.date,
save.fn = paste0('single_pt_cbc_', tolower(proc.option), '_analytic')
)
}
}
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 72997
## Number of non-duplicated first PROC_NAME rows: 67141
## Number of non-duplicated second PROC_NAME rows: 67077
## Number of paired, simultaneous values: 9511
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 3926 5585
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.50 9.90 11.30 11.67 13.20 23.10
## SD: 2.64
## Summary of BG values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.00 10.50 12.00 12.26 13.70 25.00
## SD: 2.64
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -105.4, df = 9510, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.5964648 -0.5746844
## sample estimates:
## mean difference
## -0.5855746
##
## Number of rows from which correlation is calculated: 9511
## First we use `cor` function to calculate:
## Correlation (R): 0.9790 R^2: 0.9585
## CI: Lower: 0.9568 Upper: 0.9601
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9790 R^2: 0.9585
## Calulated CIs: Lower: 0.9568 Upper: 0.9601
## Number of rows from which correlation is calculated: 5585
## First we use `cor` function to calculate:
## Correlation (R): 0.9553 R^2: 0.9126
## CI: Lower: 0.9081 Upper: 0.9170
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9553 R^2: 0.9126
## Calulated CIs: Lower: 0.9081 Upper: 0.9168
## Number of rows from which correlation is calculated: 3926
## First we use `cor` function to calculate:
## Correlation (R): 0.9885 R^2: 0.9771
## CI: Lower: 0.9756 Upper: 0.9785
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9885 R^2: 0.9771
## Calulated CIs: Lower: 0.9756 Upper: 0.9785
## PICU (R: 0.9553) vs CICU (R: 0.9885): 0.0000
## Number of rows from which correlation is calculated: 9511
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5856
## Limits: [-1.65, 0.48]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.6663776 -1.6286529 -0.5964648
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5746844 0.4575037 0.4952284
## Number of rows from which correlation is calculated: 5585
## B-A Analysis of CBC - BG in DEPT PICU
## Mean difference (bias): -0.6221
## Limits: [-1.83, 0.58]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.8560327 -1.8001222 -0.6382707
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.6059907 0.5558608 0.6117713
## Number of rows from which correlation is calculated: 3926
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.89197, p-value < 2.2e-16
##
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5336
## Limits: [-1.34, 0.27]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.3593306 -1.3148932 -0.5463991
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5207431 0.2477510 0.2921885
## Number of rows from which correlation is calculated: 9511
## Lower 2.50 %: -1.500 Upper 9.75 %: -1.000
## New number of rows: 861
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.80361, p-value < 2.2e-16
##
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -1.1225
## Limits: [-1.40, -0.84]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.4190140 -1.3859200 -1.1320854
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.1129785 -0.8591439 -0.8260498
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -45.00 24.00 38.00 59.18 59.00 10209.00
## Summary of Time-To-Result for BG
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -45.00 11.00 15.00 21.51 20.00 8419.00
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 42881244, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 3802
## Number of non-duplicated first PROC_NAME rows: 3581
## Number of non-duplicated second PROC_NAME rows: 3575
## Number of paired, simultaneous values: 2359
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 749 1610
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.50 9.40 11.00 11.38 13.10 22.80
## SD: 2.77
## Summary of ISTAT values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.40 9.50 11.20 11.54 13.30 23.10
## SD: 3.06
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -6.7059, df = 2358, p-value = 2.496e-11
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.2073684 -0.1135303
## sample estimates:
## mean difference
## -0.1604493
##
## Number of rows from which correlation is calculated: 2359
## First we use `cor` function to calculate:
## Correlation (R): 0.9256 R^2: 0.8567
## CI: Lower: 0.8458 Upper: 0.8676
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9256 R^2: 0.8567
## Calulated CIs: Lower: 0.8456 Upper: 0.8671
## Number of rows from which correlation is calculated: 1610
## First we use `cor` function to calculate:
## Correlation (R): 0.8944 R^2: 0.8000
## CI: Lower: 0.7822 Upper: 0.8178
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8944 R^2: 0.8000
## Calulated CIs: Lower: 0.7819 Upper: 0.8169
## Number of rows from which correlation is calculated: 749
## First we use `cor` function to calculate:
## Correlation (R): 0.9231 R^2: 0.8521
## CI: Lower: 0.8322 Upper: 0.8719
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9231 R^2: 0.8521
## Calulated CIs: Lower: 0.8313 Upper: 0.8705
## PICU (R: 0.8944) vs CICU (R: 0.9231): 0.0002
## Number of rows from which correlation is calculated: 2359
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92345, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.1604
## Limits: [-2.44, 2.12]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.5194231 -2.3568908 -0.2073684
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.1135303 2.0359921 2.1985244
## Number of rows from which correlation is calculated: 1610
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.91126, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## Mean difference (bias): -0.1148
## Limits: [-2.33, 2.10]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.42117014 -2.23015758 -0.16992319
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.05964203 2.00059236 2.19160493
## Number of rows from which correlation is calculated: 749
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.94125, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.2586
## Limits: [-2.66, 2.15]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.8164556 -2.5115069 -0.3466426
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.1705804 1.9942839 2.2992327
## Number of rows from which correlation is calculated: 2359
## Lower 2.50 %: -2.405 Upper 9.75 %: -1.400
## New number of rows: 186
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.91764, p-value = 1.036e-08
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -1.7651
## Limits: [-2.33, -1.20]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.406616 -2.261181 -1.807037
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.723070 -1.268927 -1.123491
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.00 28.00 45.00 79.58 64.00 11099.00
## Summary of Time-To-Result for ISTAT
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -48.0 7.0 11.0 137.8 49.0 12058.0
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 1828526, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
Now we change parameters to alter the cutoff (min) between labs that get counted as “simultaneous” labs. We revert back to allowing multiple values per patient. We run this across both BG and ISTAT pairs (if they exist), across all sens.cutoffs values.
for (cutoff in sens.cutoffs) {
for (proc.option in c('BG', 'ISTAT')) {
if (proc.option %in% unique(labs.df$PROC_NAME)) {
runAllAnalytic(
labs.df,
cohort.df,
compare.PN = proc.option,
time.diff = cutoff,
multi.per.pt = T,
run.date = run.date,
save.fn = NA
)
} # If the PROC exists
} # Across BG vs ISTAT
} # Across cutoffs
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 60273
## Number of non-duplicated first PROC_NAME rows: 58865
## Number of non-duplicated second PROC_NAME rows: 58817
## Number of paired, simultaneous values: 58817
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 21039 37778
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.50 9.20 10.60 10.95 12.30 23.00
## SD: 2.38
## Summary of BG values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.80 9.90 11.30 11.54 12.90 25.00
## SD: 2.39
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -208.52, df = 58816, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.6011365 -0.5899409
## sample estimates:
## mean difference
## -0.5955387
##
## Number of rows from which correlation is calculated: 58817
## First we use `cor` function to calculate:
## Correlation (R): 0.9579 R^2: 0.9176
## CI: Lower: 0.9163 Upper: 0.9189
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9579 R^2: 0.9176
## Calulated CIs: Lower: 0.9163 Upper: 0.9189
## Number of rows from which correlation is calculated: 37778
## First we use `cor` function to calculate:
## Correlation (R): 0.9163 R^2: 0.8396
## CI: Lower: 0.8366 Upper: 0.8426
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9163 R^2: 0.8396
## Calulated CIs: Lower: 0.8366 Upper: 0.8425
## Number of rows from which correlation is calculated: 21039
## First we use `cor` function to calculate:
## Correlation (R): 0.9782 R^2: 0.9569
## CI: Lower: 0.9557 Upper: 0.9580
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9782 R^2: 0.9569
## Calulated CIs: Lower: 0.9557 Upper: 0.9580
## PICU (R: 0.9163) vs CICU (R: 0.9782): 0.0000
## Number of rows from which correlation is calculated: 58817
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5955
## Limits: [-1.95, 0.76]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.9628320 -1.9434405 -0.6011365
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5899409 0.7523631 0.7717546
## Number of rows from which correlation is calculated: 37778
## B-A Analysis of CBC - BG in DEPT PICU
## Mean difference (bias): -0.6394
## Limits: [-2.16, 0.88]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.1716794 -2.1446111 -0.6472178
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.6315899 0.8658033 0.8928716
## Number of rows from which correlation is calculated: 21039
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5168
## Limits: [-1.50, 0.47]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.5153491 -1.4917812 -0.5235771
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5099702 0.4582340 0.4818019
## Number of rows from which correlation is calculated: 58817
## Lower 2.50 %: -2.000 Upper 9.75 %: -1.100
## New number of rows: 4511
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.86432, p-value < 2.2e-16
##
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -1.3623
## Limits: [-1.88, -0.85]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.8929904 -1.8663025 -1.3700406
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.3546324 -0.8583705 -0.8316826
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -101.00 28.00 45.00 66.67 65.00 33795.00
## Summary of Time-To-Result for BG
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -1404.00 12.00 16.00 22.42 22.00 27487.00
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 1642601281, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 279
## Number of non-duplicated first PROC_NAME rows: 277
## Number of non-duplicated second PROC_NAME rows: 276
## Number of paired, simultaneous values: 276
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 89 187
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4.60 9.30 11.20 11.29 13.00 22.70
## SD: 2.68
## Summary of ISTAT values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.70 9.20 11.20 11.45 13.60 22.10
## SD: 3.05
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -2.1996, df = 275, p-value = 0.02867
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.30278944 -0.01677578
## sample estimates:
## mean difference
## -0.1597826
##
## Number of rows from which correlation is calculated: 276
## First we use `cor` function to calculate:
## Correlation (R): 0.9189 R^2: 0.8444
## CI: Lower: 0.8106 Upper: 0.8783
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9189 R^2: 0.8444
## Calulated CIs: Lower: 0.8070 Upper: 0.8752
## Number of rows from which correlation is calculated: 187
## First we use `cor` function to calculate:
## Correlation (R): 0.8760 R^2: 0.7675
## CI: Lower: 0.7093 Upper: 0.8256
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8760 R^2: 0.7675
## Calulated CIs: Lower: 0.7020 Upper: 0.8203
## Number of rows from which correlation is calculated: 89
## First we use `cor` function to calculate:
## Correlation (R): 0.9360 R^2: 0.8762
## CI: Lower: 0.8295 Upper: 0.9229
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9360 R^2: 0.8762
## Calulated CIs: Lower: 0.8172 Upper: 0.9170
## PICU (R: 0.8760) vs CICU (R: 0.9360): 0.0080
## Number of rows from which correlation is calculated: 276
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92483, p-value = 1.38e-10
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.1598
## Limits: [-2.53, 2.21]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.77287325 -2.27748304 -0.30278944
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.01677578 1.95791783 2.45330803
## Number of rows from which correlation is calculated: 187
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.86028, p-value = 4.241e-12
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## Mean difference (bias): -0.0979
## Limits: [-2.42, 2.22]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.71161177 -2.12052755 -0.26849228
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## 0.07277035 1.92480563 2.51588985
## Number of rows from which correlation is calculated: 89
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.98956, p-value = 0.7056
##
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.2899
## Limits: [-2.75, 2.17]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.20230636 -2.28816417 -0.55377776
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.02599752 1.70838889 2.62253108
## Number of rows from which correlation is calculated: 276
## Lower 2.50 %: -2.600 Upper 9.75 %: -1.400
## New number of rows: 23
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.90228, p-value = 0.02817
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -1.8174
## Limits: [-2.55, -1.08]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.8298591 -2.2699959 -1.9790099
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.6557727 -1.3647867 -0.8049235
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.00 26.00 45.50 67.96 69.25 3135.00
## Summary of Time-To-Result for ISTAT
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.0 6.0 12.0 164.9 45.0 12058.0
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 24836, p-value = 1.623e-05
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 76385
## Number of non-duplicated first PROC_NAME rows: 69438
## Number of non-duplicated second PROC_NAME rows: 69336
## Number of paired, simultaneous values: 69336
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 25469 43867
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.50 9.30 10.70 10.97 12.40 23.20
## SD: 2.40
## Summary of BG values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.80 9.90 11.30 11.55 12.90 25.00
## SD: 2.41
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -212.86, df = 69335, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.5817589 -0.5711429
## sample estimates:
## mean difference
## -0.5764509
##
## Number of rows from which correlation is calculated: 69336
## First we use `cor` function to calculate:
## Correlation (R): 0.9560 R^2: 0.9139
## CI: Lower: 0.9126 Upper: 0.9151
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9560 R^2: 0.9139
## Calulated CIs: Lower: 0.9126 Upper: 0.9151
## Number of rows from which correlation is calculated: 43867
## First we use `cor` function to calculate:
## Correlation (R): 0.9153 R^2: 0.8378
## CI: Lower: 0.8350 Upper: 0.8407
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9153 R^2: 0.8378
## Calulated CIs: Lower: 0.8350 Upper: 0.8406
## Number of rows from which correlation is calculated: 25469
## First we use `cor` function to calculate:
## Correlation (R): 0.9740 R^2: 0.9487
## CI: Lower: 0.9474 Upper: 0.9499
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9740 R^2: 0.9487
## Calulated CIs: Lower: 0.9474 Upper: 0.9499
## PICU (R: 0.9153) vs CICU (R: 0.9740): 0.0000
## Number of rows from which correlation is calculated: 69336
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5765
## Limits: [-1.97, 0.82]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.9833404 -1.9649529 -0.5817589
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5711429 0.8120511 0.8304386
## Number of rows from which correlation is calculated: 43867
## B-A Analysis of CBC - BG in DEPT PICU
## Mean difference (bias): -0.6314
## Limits: [-2.17, 0.91]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.1818758 -2.1564412 -0.6387030
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.6240184 0.8937198 0.9191544
## Number of rows from which correlation is calculated: 25469
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.4819
## Limits: [-1.57, 0.61]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.5850267 -1.5613379 -0.4887144
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.4750376 0.5975858 0.6212747
## Number of rows from which correlation is calculated: 69336
## Lower 2.50 %: -2.000 Upper 9.75 %: -1.100
## New number of rows: 5337
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -1.3618
## Limits: [-1.88, -0.84]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.8938294 -1.8691825 -1.3689475
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.3547175 -0.8544825 -0.8298356
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -101.00 28.00 45.00 68.55 66.00 33795.00
## Summary of Time-To-Result for BG
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -1404.00 12.00 16.00 22.61 22.00 27487.00
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 2281701961, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 5185
## Number of non-duplicated first PROC_NAME rows: 4358
## Number of non-duplicated second PROC_NAME rows: 4332
## Number of paired, simultaneous values: 4332
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 1594 2738
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.70 9.40 11.00 11.28 12.90 22.80
## SD: 2.75
## Summary of ISTAT values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.40 9.20 11.20 11.37 13.30 23.80
## SD: 3.06
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -4.4245, df = 4331, p-value = 9.903e-06
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.13371680 -0.05160176
## sample estimates:
## mean difference
## -0.09265928
##
## Number of rows from which correlation is calculated: 4332
## First we use `cor` function to calculate:
## Correlation (R): 0.8931 R^2: 0.7976
## CI: Lower: 0.7866 Upper: 0.8086
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8931 R^2: 0.7976
## Calulated CIs: Lower: 0.7866 Upper: 0.8081
## Number of rows from which correlation is calculated: 2738
## First we use `cor` function to calculate:
## Correlation (R): 0.8619 R^2: 0.7429
## CI: Lower: 0.7260 Upper: 0.7598
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8619 R^2: 0.7429
## Calulated CIs: Lower: 0.7258 Upper: 0.7591
## Number of rows from which correlation is calculated: 1594
## First we use `cor` function to calculate:
## Correlation (R): 0.8761 R^2: 0.7675
## CI: Lower: 0.7472 Upper: 0.7879
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8761 R^2: 0.7675
## Calulated CIs: Lower: 0.7468 Upper: 0.7868
## PICU (R: 0.8619) vs CICU (R: 0.8761): 0.0660
## Number of rows from which correlation is calculated: 4332
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.93295, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.0927
## Limits: [-2.79, 2.61]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.86538853 -2.72316110 -0.13371680
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.05160176 2.53784254 2.68006997
## Number of rows from which correlation is calculated: 2738
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92478, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## Mean difference (bias): -0.0334
## Limits: [-2.57, 2.50]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.65454131 -2.48650519 -0.08188988
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## 0.01512582 2.41974113 2.58777725
## Number of rows from which correlation is calculated: 1594
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.94352, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.1945
## Limits: [-3.15, 2.76]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.2757660 -3.0193509 -0.2685000
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.1204586 2.6303923 2.8868074
## Number of rows from which correlation is calculated: 4332
## Lower 2.50 %: -2.872 Upper 9.75 %: -1.600
## New number of rows: 325
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92294, p-value = 6.832e-12
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -2.0468
## Limits: [-2.74, -1.35]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.810201 -2.675908 -2.085536
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -2.008002 -1.417630 -1.283337
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.00 29.00 47.00 74.08 65.00 11099.00
## Summary of Time-To-Result for ISTAT
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -48.0 7.0 11.0 120.8 38.0 12058.0
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 6414047, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 90493
## Number of non-duplicated first PROC_NAME rows: 74478
## Number of non-duplicated second PROC_NAME rows: 73790
## Number of paired, simultaneous values: 73790
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 27956 45834
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.30 9.30 10.70 10.99 12.40 23.20
## SD: 2.41
## Summary of BG values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.80 9.90 11.30 11.56 13.00 25.00
## SD: 2.42
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -200.94, df = 73789, p-value < 2.2e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.5732856 -0.5622097
## sample estimates:
## mean difference
## -0.5677477
##
## Number of rows from which correlation is calculated: 73790
## First we use `cor` function to calculate:
## Correlation (R): 0.9496 R^2: 0.9018
## CI: Lower: 0.9004 Upper: 0.9032
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9496 R^2: 0.9018
## Calulated CIs: Lower: 0.9004 Upper: 0.9031
## Number of rows from which correlation is calculated: 45834
## First we use `cor` function to calculate:
## Correlation (R): 0.9082 R^2: 0.8248
## CI: Lower: 0.8218 Upper: 0.8278
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9082 R^2: 0.8248
## Calulated CIs: Lower: 0.8219 Upper: 0.8277
## Number of rows from which correlation is calculated: 27956
## First we use `cor` function to calculate:
## Correlation (R): 0.9636 R^2: 0.9285
## CI: Lower: 0.9268 Upper: 0.9301
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.9636 R^2: 0.9285
## Calulated CIs: Lower: 0.9269 Upper: 0.9301
## PICU (R: 0.9082) vs CICU (R: 0.9636): 0.0000
## Number of rows from which correlation is calculated: 73790
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.5677
## Limits: [-2.07, 0.94]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.0816934 -2.0625093 -0.5732856
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.5622097 0.9270140 0.9461980
## Number of rows from which correlation is calculated: 45834
## B-A Analysis of CBC - BG in DEPT PICU
## Mean difference (bias): -0.6242
## Limits: [-2.23, 0.98]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -2.2444798 -2.2184729 -0.6317145
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.6166994 0.9700591 0.9960660
## Number of rows from which correlation is calculated: 27956
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -0.4752
## Limits: [-1.77, 0.82]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.7867564 -1.7598609 -0.4829465
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.4674183 0.8094960 0.8363916
## Number of rows from which correlation is calculated: 73790
## Lower 2.50 %: -2.100 Upper 9.75 %: -1.100
## New number of rows: 6316
## B-A Analysis of CBC - BG in DEPT PICU
## B-A Analysis of CBC - BG in DEPT CICU
## Mean difference (bias): -1.3921
## Limits: [-1.96, -0.82]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -1.9772939 -1.9523274 -1.3993383
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -1.3849239 -0.8319348 -0.8069683
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -160.00 28.00 45.00 68.93 66.00 33795.00
## Summary of Time-To-Result for BG
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -1404.00 12.00 16.00 22.47 22.00 27487.00
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 2580593141, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0
##
## Number of component numeric rows in input data frame: 461758
## Number of paired, simultaneous values meeting cutoff: 11795
## Number of non-duplicated first PROC_NAME rows: 7590
## Number of non-duplicated second PROC_NAME rows: 7017
## Number of paired, simultaneous values: 7017
## Number of duplicated ORDER_PROC_KEY.x values: 0
##
## CICU PICU
## 3180 3837
## Summary of CBC values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 2.10 9.60 11.20 11.45 13.10 23.10
## SD: 2.72
## Summary of ISTAT values:
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.40 9.50 11.60 11.62 13.60 25.20
## SD: 3.04
##
## Paired t-test
##
## data: df$NUM_VAL.x and df$NUM_VAL.y
## t = -8.2018, df = 7016, p-value = 2.793e-16
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
## -0.2090442 -0.1283934
## sample estimates:
## mean difference
## -0.1687188
##
## Number of rows from which correlation is calculated: 7017
## First we use `cor` function to calculate:
## Correlation (R): 0.8264 R^2: 0.6829
## CI: Lower: 0.6704 Upper: 0.6954
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.8264 R^2: 0.6829
## Calulated CIs: Lower: 0.6704 Upper: 0.6950
## Number of rows from which correlation is calculated: 3837
## First we use `cor` function to calculate:
## Correlation (R): 0.7934 R^2: 0.6295
## CI: Lower: 0.6106 Upper: 0.6485
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.7934 R^2: 0.6295
## Calulated CIs: Lower: 0.6106 Upper: 0.6478
## Number of rows from which correlation is calculated: 3180
## First we use `cor` function to calculate:
## Correlation (R): 0.7703 R^2: 0.5934
## CI: Lower: 0.5712 Upper: 0.6155
## Now we use `cor.test` and `conf.int` to calculate:
## Calculated R: 0.7703 R^2: 0.5934
## Calulated CIs: Lower: 0.5712 Upper: 0.6148
## PICU (R: 0.7934) vs CICU (R: 0.7703): 0.0131
## Number of rows from which correlation is calculated: 7017
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.1687
## Limits: [-3.55, 3.21]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.6160045 -3.4763132 -0.2090442
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.1283934 3.1388755 3.2785669
## Number of rows from which correlation is calculated: 3837
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.93123, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## Mean difference (bias): 0.0273
## Limits: [-3.00, 3.06]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.08542107 -2.91603202 -0.02158540
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## 0.07621141 2.97065803 3.14004708
## Number of rows from which correlation is calculated: 3180
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.95757, p-value < 2.2e-16
##
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -0.4053
## Limits: [-4.11, 3.30]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -4.2228532 -3.9952482 -0.4709555
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -0.3395477 3.1847450 3.4123501
## Number of rows from which correlation is calculated: 7017
## Lower 2.50 %: -4.000 Upper 9.75 %: -2.100
## New number of rows: 529
##
## Shapiro-Wilk normality test
##
## data: limited.df$diff
## W = 0.92417, p-value = 1.11e-15
##
## B-A Analysis of CBC - ISTAT in DEPT PICU
## B-A Analysis of CBC - ISTAT in DEPT CICU
## Mean difference (bias): -2.7883
## Limits: [-3.85, -1.73]
## CIs of mean and limits:
## lower.limit.ci.lower lower.limit.ci.upper mean.diff.ci.lower
## -3.926723 -3.766929 -2.834408
## mean.diff.ci.upper upper.limit.ci.lower upper.limit.ci.upper
## -2.742151 -1.809631 -1.649836
## Summary of Time-To-Result for CBC
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -38.00 27.00 45.00 69.16 65.00 11099.00
## Summary of Time-To-Result for ISTAT
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## -51.0 7.0 10.0 117.9 28.0 12002.0
##
## Wilcoxon signed rank test with continuity correction
##
## data: time_to_result$TTR[time_to_result$SRC == PN[1]] and time_to_result$TTR[time_to_result$SRC == PN[2]]
## V = 17157343, p-value < 2.2e-16
## alternative hypothesis: true location shift is not equal to 0